

#include "core/components_ng/pattern/mycircle/mycircle_layout_algorithm.h"

#include "core/components_ng/base/frame_node.h"
#include "core/components_ng/pattern/mycircle/mycircle_layout_property.h"

namespace OHOS::Ace::NG {

std::optional<SizeF> MyCircleLayoutAlgorithm::MeasureContent(
    const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper)
{
    if (contentConstraint.selfIdealSize.IsValid()) {
        return contentConstraint.selfIdealSize.ConvertToSizeT();
    }
    auto mycircleLayoutProperty = DynamicCast<MyCircleLayoutProperty>(layoutWrapper->GetLayoutProperty());
    CHECK_NULL_RETURN(mycircleLayoutProperty, std::nullopt);
    auto radius = mycircleLayoutProperty->GetRadius().value_or(30.0_vp).ConvertToPx();
    auto edgeWidth = mycircleLayoutProperty->GetEdgeWidth().value_or(1.0_vp).ConvertToPx();
    CHECK_NULL_RETURN(mycircleLayoutProperty, std::nullopt);
    SizeF componentSize((2 * radius + edgeWidth), (2 * radius + edgeWidth));
    return contentConstraint.Constrain(componentSize);
}

} // namespace OHOS::Ace::NG